<?php


abstract class BaseTurno extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $paciente_id;


	
	protected $medico_id;


	
	protected $estudio_id;


	
	protected $dia;


	
	protected $inicio;


	
	protected $fin;


	
	protected $activo = 1;


	
	protected $sobreturno = 0;


	
	protected $created_by;


	
	protected $update_by;


	
	protected $updated_fields;


	
	protected $id;

	
	protected $aPaciente;

	
	protected $aUsuarioRelatedByMedicoId;

	
	protected $aEstudio;

	
	protected $aUsuarioRelatedByCreatedBy;

	
	protected $aUsuarioRelatedByUpdateBy;

	
	protected $collTurnoCambioEstados;

	
	protected $lastTurnoCambioEstadoCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getPacienteId()
	{

		return $this->paciente_id;
	}

	
	public function getMedicoId()
	{

		return $this->medico_id;
	}

	
	public function getEstudioId()
	{

		return $this->estudio_id;
	}

	
	public function getDia($format = 'Y-m-d')
	{

		if ($this->dia === null || $this->dia === '') {
			return null;
		} elseif (!is_int($this->dia)) {
						$ts = strtotime($this->dia);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [dia] as date/time value: " . var_export($this->dia, true));
			}
		} else {
			$ts = $this->dia;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getInicio($format = 'H:i:s')
	{

		if ($this->inicio === null || $this->inicio === '') {
			return null;
		} elseif (!is_int($this->inicio)) {
						$ts = strtotime($this->inicio);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [inicio] as date/time value: " . var_export($this->inicio, true));
			}
		} else {
			$ts = $this->inicio;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getFin($format = 'H:i:s')
	{

		if ($this->fin === null || $this->fin === '') {
			return null;
		} elseif (!is_int($this->fin)) {
						$ts = strtotime($this->fin);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fin] as date/time value: " . var_export($this->fin, true));
			}
		} else {
			$ts = $this->fin;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getActivo()
	{

		return $this->activo;
	}

	
	public function getSobreturno()
	{

		return $this->sobreturno;
	}

	
	public function getCreatedBy()
	{

		return $this->created_by;
	}

	
	public function getUpdateBy()
	{

		return $this->update_by;
	}

	
	public function getUpdatedFields()
	{

		return $this->updated_fields;
	}

	
	public function getId()
	{

		return $this->id;
	}

	
	public function setPacienteId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->paciente_id !== $v) {
			$this->paciente_id = $v;
			$this->modifiedColumns[] = TurnoPeer::PACIENTE_ID;
		}

		if ($this->aPaciente !== null && $this->aPaciente->getId() !== $v) {
			$this->aPaciente = null;
		}

	} 
	
	public function setMedicoId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->medico_id !== $v) {
			$this->medico_id = $v;
			$this->modifiedColumns[] = TurnoPeer::MEDICO_ID;
		}

		if ($this->aUsuarioRelatedByMedicoId !== null && $this->aUsuarioRelatedByMedicoId->getId() !== $v) {
			$this->aUsuarioRelatedByMedicoId = null;
		}

	} 
	
	public function setEstudioId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->estudio_id !== $v) {
			$this->estudio_id = $v;
			$this->modifiedColumns[] = TurnoPeer::ESTUDIO_ID;
		}

		if ($this->aEstudio !== null && $this->aEstudio->getId() !== $v) {
			$this->aEstudio = null;
		}

	} 
	
	public function setDia($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [dia] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->dia !== $ts) {
			$this->dia = $ts;
			$this->modifiedColumns[] = TurnoPeer::DIA;
		}

	} 
	
	public function setInicio($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [inicio] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->inicio !== $ts) {
			$this->inicio = $ts;
			$this->modifiedColumns[] = TurnoPeer::INICIO;
		}

	} 
	
	public function setFin($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fin] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fin !== $ts) {
			$this->fin = $ts;
			$this->modifiedColumns[] = TurnoPeer::FIN;
		}

	} 
	
	public function setActivo($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->activo !== $v || $v === 1) {
			$this->activo = $v;
			$this->modifiedColumns[] = TurnoPeer::ACTIVO;
		}

	} 
	
	public function setSobreturno($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->sobreturno !== $v || $v === 0) {
			$this->sobreturno = $v;
			$this->modifiedColumns[] = TurnoPeer::SOBRETURNO;
		}

	} 
	
	public function setCreatedBy($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->created_by !== $v) {
			$this->created_by = $v;
			$this->modifiedColumns[] = TurnoPeer::CREATED_BY;
		}

		if ($this->aUsuarioRelatedByCreatedBy !== null && $this->aUsuarioRelatedByCreatedBy->getId() !== $v) {
			$this->aUsuarioRelatedByCreatedBy = null;
		}

	} 
	
	public function setUpdateBy($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->update_by !== $v) {
			$this->update_by = $v;
			$this->modifiedColumns[] = TurnoPeer::UPDATE_BY;
		}

		if ($this->aUsuarioRelatedByUpdateBy !== null && $this->aUsuarioRelatedByUpdateBy->getId() !== $v) {
			$this->aUsuarioRelatedByUpdateBy = null;
		}

	} 
	
	public function setUpdatedFields($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->updated_fields !== $v) {
			$this->updated_fields = $v;
			$this->modifiedColumns[] = TurnoPeer::UPDATED_FIELDS;
		}

	} 
	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = TurnoPeer::ID;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->paciente_id = $rs->getInt($startcol + 0);

			$this->medico_id = $rs->getInt($startcol + 1);

			$this->estudio_id = $rs->getInt($startcol + 2);

			$this->dia = $rs->getDate($startcol + 3, null);

			$this->inicio = $rs->getTime($startcol + 4, null);

			$this->fin = $rs->getTime($startcol + 5, null);

			$this->activo = $rs->getInt($startcol + 6);

			$this->sobreturno = $rs->getInt($startcol + 7);

			$this->created_by = $rs->getInt($startcol + 8);

			$this->update_by = $rs->getInt($startcol + 9);

			$this->updated_fields = $rs->get($startcol + 10);

			$this->id = $rs->getInt($startcol + 11);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 12; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Turno object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TurnoPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			TurnoPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TurnoPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aPaciente !== null) {
				if ($this->aPaciente->isModified()) {
					$affectedRows += $this->aPaciente->save($con);
				}
				$this->setPaciente($this->aPaciente);
			}

			if ($this->aUsuarioRelatedByMedicoId !== null) {
				if ($this->aUsuarioRelatedByMedicoId->isModified()) {
					$affectedRows += $this->aUsuarioRelatedByMedicoId->save($con);
				}
				$this->setUsuarioRelatedByMedicoId($this->aUsuarioRelatedByMedicoId);
			}

			if ($this->aEstudio !== null) {
				if ($this->aEstudio->isModified()) {
					$affectedRows += $this->aEstudio->save($con);
				}
				$this->setEstudio($this->aEstudio);
			}

			if ($this->aUsuarioRelatedByCreatedBy !== null) {
				if ($this->aUsuarioRelatedByCreatedBy->isModified()) {
					$affectedRows += $this->aUsuarioRelatedByCreatedBy->save($con);
				}
				$this->setUsuarioRelatedByCreatedBy($this->aUsuarioRelatedByCreatedBy);
			}

			if ($this->aUsuarioRelatedByUpdateBy !== null) {
				if ($this->aUsuarioRelatedByUpdateBy->isModified()) {
					$affectedRows += $this->aUsuarioRelatedByUpdateBy->save($con);
				}
				$this->setUsuarioRelatedByUpdateBy($this->aUsuarioRelatedByUpdateBy);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = TurnoPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += TurnoPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collTurnoCambioEstados !== null) {
				foreach($this->collTurnoCambioEstados as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aPaciente !== null) {
				if (!$this->aPaciente->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aPaciente->getValidationFailures());
				}
			}

			if ($this->aUsuarioRelatedByMedicoId !== null) {
				if (!$this->aUsuarioRelatedByMedicoId->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aUsuarioRelatedByMedicoId->getValidationFailures());
				}
			}

			if ($this->aEstudio !== null) {
				if (!$this->aEstudio->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aEstudio->getValidationFailures());
				}
			}

			if ($this->aUsuarioRelatedByCreatedBy !== null) {
				if (!$this->aUsuarioRelatedByCreatedBy->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aUsuarioRelatedByCreatedBy->getValidationFailures());
				}
			}

			if ($this->aUsuarioRelatedByUpdateBy !== null) {
				if (!$this->aUsuarioRelatedByUpdateBy->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aUsuarioRelatedByUpdateBy->getValidationFailures());
				}
			}


			if (($retval = TurnoPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collTurnoCambioEstados !== null) {
					foreach($this->collTurnoCambioEstados as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TurnoPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getPacienteId();
				break;
			case 1:
				return $this->getMedicoId();
				break;
			case 2:
				return $this->getEstudioId();
				break;
			case 3:
				return $this->getDia();
				break;
			case 4:
				return $this->getInicio();
				break;
			case 5:
				return $this->getFin();
				break;
			case 6:
				return $this->getActivo();
				break;
			case 7:
				return $this->getSobreturno();
				break;
			case 8:
				return $this->getCreatedBy();
				break;
			case 9:
				return $this->getUpdateBy();
				break;
			case 10:
				return $this->getUpdatedFields();
				break;
			case 11:
				return $this->getId();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TurnoPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getPacienteId(),
			$keys[1] => $this->getMedicoId(),
			$keys[2] => $this->getEstudioId(),
			$keys[3] => $this->getDia(),
			$keys[4] => $this->getInicio(),
			$keys[5] => $this->getFin(),
			$keys[6] => $this->getActivo(),
			$keys[7] => $this->getSobreturno(),
			$keys[8] => $this->getCreatedBy(),
			$keys[9] => $this->getUpdateBy(),
			$keys[10] => $this->getUpdatedFields(),
			$keys[11] => $this->getId(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TurnoPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setPacienteId($value);
				break;
			case 1:
				$this->setMedicoId($value);
				break;
			case 2:
				$this->setEstudioId($value);
				break;
			case 3:
				$this->setDia($value);
				break;
			case 4:
				$this->setInicio($value);
				break;
			case 5:
				$this->setFin($value);
				break;
			case 6:
				$this->setActivo($value);
				break;
			case 7:
				$this->setSobreturno($value);
				break;
			case 8:
				$this->setCreatedBy($value);
				break;
			case 9:
				$this->setUpdateBy($value);
				break;
			case 10:
				$this->setUpdatedFields($value);
				break;
			case 11:
				$this->setId($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TurnoPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setPacienteId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setMedicoId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setEstudioId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setDia($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setInicio($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setFin($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setActivo($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setSobreturno($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setCreatedBy($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setUpdateBy($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setUpdatedFields($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setId($arr[$keys[11]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(TurnoPeer::DATABASE_NAME);

		if ($this->isColumnModified(TurnoPeer::PACIENTE_ID)) $criteria->add(TurnoPeer::PACIENTE_ID, $this->paciente_id);
		if ($this->isColumnModified(TurnoPeer::MEDICO_ID)) $criteria->add(TurnoPeer::MEDICO_ID, $this->medico_id);
		if ($this->isColumnModified(TurnoPeer::ESTUDIO_ID)) $criteria->add(TurnoPeer::ESTUDIO_ID, $this->estudio_id);
		if ($this->isColumnModified(TurnoPeer::DIA)) $criteria->add(TurnoPeer::DIA, $this->dia);
		if ($this->isColumnModified(TurnoPeer::INICIO)) $criteria->add(TurnoPeer::INICIO, $this->inicio);
		if ($this->isColumnModified(TurnoPeer::FIN)) $criteria->add(TurnoPeer::FIN, $this->fin);
		if ($this->isColumnModified(TurnoPeer::ACTIVO)) $criteria->add(TurnoPeer::ACTIVO, $this->activo);
		if ($this->isColumnModified(TurnoPeer::SOBRETURNO)) $criteria->add(TurnoPeer::SOBRETURNO, $this->sobreturno);
		if ($this->isColumnModified(TurnoPeer::CREATED_BY)) $criteria->add(TurnoPeer::CREATED_BY, $this->created_by);
		if ($this->isColumnModified(TurnoPeer::UPDATE_BY)) $criteria->add(TurnoPeer::UPDATE_BY, $this->update_by);
		if ($this->isColumnModified(TurnoPeer::UPDATED_FIELDS)) $criteria->add(TurnoPeer::UPDATED_FIELDS, $this->updated_fields);
		if ($this->isColumnModified(TurnoPeer::ID)) $criteria->add(TurnoPeer::ID, $this->id);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(TurnoPeer::DATABASE_NAME);

		$criteria->add(TurnoPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setPacienteId($this->paciente_id);

		$copyObj->setMedicoId($this->medico_id);

		$copyObj->setEstudioId($this->estudio_id);

		$copyObj->setDia($this->dia);

		$copyObj->setInicio($this->inicio);

		$copyObj->setFin($this->fin);

		$copyObj->setActivo($this->activo);

		$copyObj->setSobreturno($this->sobreturno);

		$copyObj->setCreatedBy($this->created_by);

		$copyObj->setUpdateBy($this->update_by);

		$copyObj->setUpdatedFields($this->updated_fields);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getTurnoCambioEstados() as $relObj) {
				$copyObj->addTurnoCambioEstado($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new TurnoPeer();
		}
		return self::$peer;
	}

	
	public function setPaciente($v)
	{


		if ($v === null) {
			$this->setPacienteId(NULL);
		} else {
			$this->setPacienteId($v->getId());
		}


		$this->aPaciente = $v;
	}


	
	public function getPaciente($con = null)
	{
		if ($this->aPaciente === null && ($this->paciente_id !== null)) {
						include_once 'lib/model/om/BasePacientePeer.php';

			$this->aPaciente = PacientePeer::retrieveByPK($this->paciente_id, $con);

			
		}
		return $this->aPaciente;
	}

	
	public function setUsuarioRelatedByMedicoId($v)
	{


		if ($v === null) {
			$this->setMedicoId(NULL);
		} else {
			$this->setMedicoId($v->getId());
		}


		$this->aUsuarioRelatedByMedicoId = $v;
	}


	
	public function getUsuarioRelatedByMedicoId($con = null)
	{
		if ($this->aUsuarioRelatedByMedicoId === null && ($this->medico_id !== null)) {
						include_once 'lib/model/om/BaseUsuarioPeer.php';

			$this->aUsuarioRelatedByMedicoId = UsuarioPeer::retrieveByPK($this->medico_id, $con);

			
		}
		return $this->aUsuarioRelatedByMedicoId;
	}

	
	public function setEstudio($v)
	{


		if ($v === null) {
			$this->setEstudioId(NULL);
		} else {
			$this->setEstudioId($v->getId());
		}


		$this->aEstudio = $v;
	}


	
	public function getEstudio($con = null)
	{
		if ($this->aEstudio === null && ($this->estudio_id !== null)) {
						include_once 'lib/model/om/BaseEstudioPeer.php';

			$this->aEstudio = EstudioPeer::retrieveByPK($this->estudio_id, $con);

			
		}
		return $this->aEstudio;
	}

	
	public function setUsuarioRelatedByCreatedBy($v)
	{


		if ($v === null) {
			$this->setCreatedBy(NULL);
		} else {
			$this->setCreatedBy($v->getId());
		}


		$this->aUsuarioRelatedByCreatedBy = $v;
	}


	
	public function getUsuarioRelatedByCreatedBy($con = null)
	{
		if ($this->aUsuarioRelatedByCreatedBy === null && ($this->created_by !== null)) {
						include_once 'lib/model/om/BaseUsuarioPeer.php';

			$this->aUsuarioRelatedByCreatedBy = UsuarioPeer::retrieveByPK($this->created_by, $con);

			
		}
		return $this->aUsuarioRelatedByCreatedBy;
	}

	
	public function setUsuarioRelatedByUpdateBy($v)
	{


		if ($v === null) {
			$this->setUpdateBy(NULL);
		} else {
			$this->setUpdateBy($v->getId());
		}


		$this->aUsuarioRelatedByUpdateBy = $v;
	}


	
	public function getUsuarioRelatedByUpdateBy($con = null)
	{
		if ($this->aUsuarioRelatedByUpdateBy === null && ($this->update_by !== null)) {
						include_once 'lib/model/om/BaseUsuarioPeer.php';

			$this->aUsuarioRelatedByUpdateBy = UsuarioPeer::retrieveByPK($this->update_by, $con);

			
		}
		return $this->aUsuarioRelatedByUpdateBy;
	}

	
	public function initTurnoCambioEstados()
	{
		if ($this->collTurnoCambioEstados === null) {
			$this->collTurnoCambioEstados = array();
		}
	}

	
	public function getTurnoCambioEstados($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseTurnoCambioEstadoPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTurnoCambioEstados === null) {
			if ($this->isNew()) {
			   $this->collTurnoCambioEstados = array();
			} else {

				$criteria->add(TurnoCambioEstadoPeer::TURNO_ID, $this->getId());

				TurnoCambioEstadoPeer::addSelectColumns($criteria);
				$this->collTurnoCambioEstados = TurnoCambioEstadoPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(TurnoCambioEstadoPeer::TURNO_ID, $this->getId());

				TurnoCambioEstadoPeer::addSelectColumns($criteria);
				if (!isset($this->lastTurnoCambioEstadoCriteria) || !$this->lastTurnoCambioEstadoCriteria->equals($criteria)) {
					$this->collTurnoCambioEstados = TurnoCambioEstadoPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastTurnoCambioEstadoCriteria = $criteria;
		return $this->collTurnoCambioEstados;
	}

	
	public function countTurnoCambioEstados($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseTurnoCambioEstadoPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(TurnoCambioEstadoPeer::TURNO_ID, $this->getId());

		return TurnoCambioEstadoPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addTurnoCambioEstado(TurnoCambioEstado $l)
	{
		$this->collTurnoCambioEstados[] = $l;
		$l->setTurno($this);
	}


	
	public function getTurnoCambioEstadosJoinTurnoEstado($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseTurnoCambioEstadoPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTurnoCambioEstados === null) {
			if ($this->isNew()) {
				$this->collTurnoCambioEstados = array();
			} else {

				$criteria->add(TurnoCambioEstadoPeer::TURNO_ID, $this->getId());

				$this->collTurnoCambioEstados = TurnoCambioEstadoPeer::doSelectJoinTurnoEstado($criteria, $con);
			}
		} else {
									
			$criteria->add(TurnoCambioEstadoPeer::TURNO_ID, $this->getId());

			if (!isset($this->lastTurnoCambioEstadoCriteria) || !$this->lastTurnoCambioEstadoCriteria->equals($criteria)) {
				$this->collTurnoCambioEstados = TurnoCambioEstadoPeer::doSelectJoinTurnoEstado($criteria, $con);
			}
		}
		$this->lastTurnoCambioEstadoCriteria = $criteria;

		return $this->collTurnoCambioEstados;
	}


	
	public function getTurnoCambioEstadosJoinUsuarioRelatedByCreatedBy($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseTurnoCambioEstadoPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTurnoCambioEstados === null) {
			if ($this->isNew()) {
				$this->collTurnoCambioEstados = array();
			} else {

				$criteria->add(TurnoCambioEstadoPeer::TURNO_ID, $this->getId());

				$this->collTurnoCambioEstados = TurnoCambioEstadoPeer::doSelectJoinUsuarioRelatedByCreatedBy($criteria, $con);
			}
		} else {
									
			$criteria->add(TurnoCambioEstadoPeer::TURNO_ID, $this->getId());

			if (!isset($this->lastTurnoCambioEstadoCriteria) || !$this->lastTurnoCambioEstadoCriteria->equals($criteria)) {
				$this->collTurnoCambioEstados = TurnoCambioEstadoPeer::doSelectJoinUsuarioRelatedByCreatedBy($criteria, $con);
			}
		}
		$this->lastTurnoCambioEstadoCriteria = $criteria;

		return $this->collTurnoCambioEstados;
	}


	
	public function getTurnoCambioEstadosJoinUsuarioRelatedByUpdateBy($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseTurnoCambioEstadoPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTurnoCambioEstados === null) {
			if ($this->isNew()) {
				$this->collTurnoCambioEstados = array();
			} else {

				$criteria->add(TurnoCambioEstadoPeer::TURNO_ID, $this->getId());

				$this->collTurnoCambioEstados = TurnoCambioEstadoPeer::doSelectJoinUsuarioRelatedByUpdateBy($criteria, $con);
			}
		} else {
									
			$criteria->add(TurnoCambioEstadoPeer::TURNO_ID, $this->getId());

			if (!isset($this->lastTurnoCambioEstadoCriteria) || !$this->lastTurnoCambioEstadoCriteria->equals($criteria)) {
				$this->collTurnoCambioEstados = TurnoCambioEstadoPeer::doSelectJoinUsuarioRelatedByUpdateBy($criteria, $con);
			}
		}
		$this->lastTurnoCambioEstadoCriteria = $criteria;

		return $this->collTurnoCambioEstados;
	}

} 